//
// Description: 167. 两数之和 II - 输入有序数组
// Created by Loading on 2025/4/5.
//

#include <bits/stdc++.h>

using namespace std;

vector<int> twoSum(vector<int> &numbers, int target) {
    for (int i = 0, j = (int) numbers.size() - 1; i < j;) {
        if (numbers[i] + numbers[j] > target) {
            --j;
        } else if (numbers[i] + numbers[j] < target) {
            ++i;
        } else {
            return {i + 1, j + 1};
        }
    }
    return {};
}

int main() {
    vector<int> numbers{2, 7, 8, 11};
    int target = 9;

    auto res = twoSum(numbers, target);

    for (auto &x : res) {
        cout << x << ' ';
    }

    return 0;
}
